﻿Imports OMANE.Common.UI
Imports OMANE.Common.UI.Theme
Imports System.ComponentModel.Composition


<OMANE.Common.ServiceInfo()> _
<Export(GetType(Common.UI.IUIService))> _
Friend Class UIServiceImpl
    Implements Common.UI.IUIService


    Private initialized As Boolean = False
    Private _mainmenu As ViewModelMainMenuImpl
    Private _statusbar As New ViewModelStatusBar
    Private _accordeonmenuV2 As ViewModelAccordeonMenuImpl

    Public Sub Initialize() Implements Common.IService.Initialize
        If Not initialized Then

            createmainmenu()
            createaccordeonmenu()
            initialized = True
        End If
    End Sub

    Private Sub createmainmenu()
        Dim menus As ViewModelMainMenuItem() = New ViewModelMainMenuItem() {
            New ViewModelMainMenuItem() With {.Title = "Fichier"}, _
            New ViewModelMainMenuItem() With {.Title = "Edition"}, _
            New ViewModelMainMenuItem() With {.Title = "Format"}, _
            New ViewModelMainMenuItem() With {.Title = "Affichage"}, _
            New ViewModelMainMenuItem() With {.Title = "Outils"}, _
            New ViewModelMainMenuItem() With {.Title = "Aides"}}

        _mainmenu = New ViewModelMainMenuImpl(menus)
        _mainmenu.SetBaseItems(menus)
    End Sub
    Private Sub createaccordeonmenu()
        Dim menus As V2ViewModelAccordeonMenuItem() = New V2ViewModelAccordeonMenuItem() {
            New V2ViewModelAccordeonMenuItem() With {.Header = "ETUDES", .Icone = StandardIcons.ICO_ETUDE}, _
            New V2ViewModelAccordeonMenuItem() With {.Header = "INVENTAIRES", .Icone = StandardIcons.ICO_INVENTAIRE}, _
            New V2ViewModelAccordeonMenuItem() With {.Header = "INDICATEURS", .Icone = StandardIcons.ICO_INDICATEURS}, _
            New V2ViewModelAccordeonMenuItem() With {.Header = "FORMATION", .Icone = StandardIcons.ICO_FORMATION}}

        menus(0).Body = New V2ViewModelTrvMenu( _
          New V2ViewModelTrvMenuItem() With {.Title = "Etudes", .Icone = StandardIcons.HOUSE})
        menus(1).Body = New V2ViewModelTrvMenu( _
          New V2ViewModelTrvMenuItem() With {.Title = "Inventaires", .Icone = StandardIcons.HOUSE})
        menus(2).Body = New V2ViewModelTrvMenu( _
          New V2ViewModelTrvMenuItem() With {.Title = "Indicateurs", .Icone = StandardIcons.HOUSE})
        menus(3).Body = New V2ViewModelTrvMenu( _
          New V2ViewModelTrvMenuItem() With {.Title = "Formation", .Icone = StandardIcons.HOUSE})

        _accordeonmenuV2 = New ViewModelAccordeonMenuImpl(menus)
        _accordeonmenuV2.SetBaseItems(menus)
    End Sub



#Region "IDisposable Support"
    Private disposedValue As Boolean ' Pour détecter les appels redondants

    ' IDisposable
    Protected Overridable Sub Dispose(ByVal disposing As Boolean)
        If Not Me.disposedValue Then
            If disposing Then
                ' TODO: supprimez l'état managé (objets managés).
            End If

            ' TODO: libérez les ressources non managées (objets non managés) et substituez la méthode Finalize() ci-dessous.
            ' TODO: définissez les champs volumineux à null.
        End If
        Me.disposedValue = True
    End Sub

    ' TODO: substituez Finalize() uniquement si Dispose(ByVal disposing As Boolean) ci-dessus comporte du code permettant de libérer des ressources non managées.
    'Protected Overrides Sub Finalize()
    '    ' Ne modifiez pas ce code. Ajoutez du code de nettoyage dans Dispose(ByVal disposing As Boolean) ci-dessus.
    '    Dispose(False)
    '    MyBase.Finalize()
    'End Sub

    ' Ce code a été ajouté par Visual Basic pour permettre l'implémentation correcte du modèle pouvant être supprimé.
    Public Sub Dispose() Implements IDisposable.Dispose
        ' Ne modifiez pas ce code. Ajoutez du code de nettoyage dans Dispose(ByVal disposing As Boolean) ci-dessus.
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub
#End Region

    Public Sub ShowDirectoryDialogBox() Implements Common.UI.IUIService.ShowDirectoryDialogBox

    End Sub

    Public Sub ShowOpenDialogBox() Implements Common.UI.IUIService.ShowOpenDialogBox

    End Sub

    Public Sub ShowSaveDialogBox() Implements Common.UI.IUIService.ShowSaveDialogBox

    End Sub

    Public ReadOnly Property MainMenu As Common.UI.ViewModelMainMenu Implements Common.UI.IUIService.ViewModelMainMenu
        Get
            Return _mainmenu
        End Get
    End Property

    Public ReadOnly Property StatusBar As Common.UI.ViewModelStatusBar Implements Common.UI.IUIService.StatusBar
        Get
            Return _statusbar
        End Get
    End Property

    Public ReadOnly Property V2ViewModelAccordeonMenu As Common.UI.V2ViewModelAccordeonMenu Implements Common.UI.IUIService.V2ViewModelAccordeonMenu
        Get
            Return _accordeonmenuV2
        End Get
    End Property

    Public Sub AddResourceDictionary(ByVal ResourceDictionary As System.Windows.ResourceDictionary) Implements Common.UI.IUIService.AddResourceDictionary
        Application.Current.Resources.MergedDictionaries.Add(ResourceDictionary)
    End Sub


    Public Sub ShowMessage(ByVal msg As Object, _
                           Optional ByVal WindowTitle As String = "OMANE", _
                           Optional ByVal Resizable As Boolean = True, _
                           Optional ByVal ShowCloseButton As Boolean = True, _
                           Optional ByVal Width As Double? = Nothing, _
                           Optional ByVal Height As Double? = Nothing) Implements Common.UI.IUIService.ShowMessage

        Dim win As New MessageWindow
        win.DataContext = msg
        win.ShowCloseButton = ShowCloseButton
        win.TitleCustom = WindowTitle
        win.ResizeMode = If(Resizable, ResizeMode.CanResizeWithGrip, ResizeMode.NoResize)
        If Width IsNot Nothing Then
            win.Width = Width.Value
            win.SizeToContent = SizeToContent.Manual
        End If
        If Height IsNot Nothing Then
            win.Height = Height.Value
            win.SizeToContent = SizeToContent.Manual
        End If
        win.ShowDialog()
    End Sub

    Public Sub ShowMessage(ByVal str As String, _
                           Optional ByVal WindowTitle As String = "OMANE", _
                           Optional ByVal Resizable As Boolean = True, _
                           Optional ByVal ShowCloseButton As Boolean = True, _
                           Optional ByVal Width As Double? = Nothing, _
                           Optional ByVal Height As Double? = Nothing) Implements Common.UI.IUIService.ShowMessage
        Dim win As New MessageWindow
        win.DataContext = str
        win.TitleCustom = WindowTitle
        win.ShowCloseButton = ShowCloseButton
        win.ResizeMode = If(Resizable, ResizeMode.CanResizeWithGrip, ResizeMode.NoResize)
        If Width IsNot Nothing Then
            win.Width = Width.Value
        End If
        If Height IsNot Nothing Then
            win.Height = Height.Value
        End If
        win.ShowDialog()
    End Sub
End Class
